<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<title>Untitled Document</title>
<script src="conUTM2LatLon.js" type="text/javascript"></script>
<script language="javascript">
function update_latlng(str){
   	var urlstr="create_gis_event_utm2latlng2.php";
	if (window.XMLHttpRequest) {
   		request = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
   		request = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	//var request = GXmlHttp.create();
	pmeters="strsql="+str;
	request.open('POST', urlstr , true); // request XML from PHP with AJAX 	call 
	request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");           
	request.setRequestHeader("Content-length", pmeters.length);            
	request.setRequestHeader("Connection", "close"); 
	request.send(pmeters); 
	request.onreadystatechange = function () { // if function
	//alert("wait");
	//alert(request.readyState);
	if (request.readyState == 4) {//if readyState == 4
			//document.write(textResponse);
		}// end if readyState == 4
	}// end function
	request.send(null); 
}// 

</script>
</head>
<body>
<form name="form1" id="form1"> 
<script>
<?php
//$link = mysql_connect("10.0.0.122", "somsawat", "s*lock9#") or die("Could not connect: " . mysql_error());
//mysql_select_db("dsccmis",$link) or die ("Can\'t use dbmapserver : " . mysql_error());
//include "../connect/connect_dsccmis.php";
$table = "gis_event";
$field_x = "tarx";
$field_y = "tary";
$pk = "evnid";
	//get  last update
	$sql = "select max(upddte) as upddte from gis_event_lastupdate";
	$rs=mysql_query($sql);
	$row=mysql_fetch_array($rs);
	$upddte=$row["upddte"];
	//get new last update
	$sql = "select max(upddte) as new_upddte from gis_event";
	$rs=mysql_query($sql);
	$new_upddte=$row["new_upddte"];
	//update  last update
	$sql = "update gis_event_lastupdate set upddte = '$new_upddte'";
	$rs=mysql_query($sql);
	
$sql = "SELECT evnid,tarx,tary FROM $table where (lat is null or lat = '') and (tarx is not null) and (tarx <> '') and (tary is not null) and (tary <> '') and (upddte > '$upddte')  order by evnid desc";
mysql_query("set names utf8");
$result = mysql_query($sql);
if (!$result)
{
	echo "no results ";
}else{
//echo "<script language=\"javascript\">\n";
//echo "function getsql(){\n";
echo "var inputx, inputy, inputzone,pk, inputsouthhemi;\n";
echo "var point,marker;\n";
echo "var strsql=' ';\n";
while($row = mysql_fetch_array($result))
{
//echo "inputx = ".$row[$field_x].";\n";
//echo "inputy = ".$row[$field_y].";\n";
//echo "inputzone =47;\n";
//echo "inputsouthhemi = false;\n";
//echo "alert('test');";
echo "pk='".$row[$pk]."';";
echo "btnToGeographic_OnClick('".$row[$field_x]."','".$row[$field_y]."','47','false');\n";
//echo "alert(tarlat)";
//echo "alert('test b');";
//echo "document.write('test');\n";
//echo "alert('test a');";
echo "strsql = strsql + 'update $table set lat='+tarlat+',lng='+tarlon+' where $pk='+ pk +';';";
//echo "document.write('update $table set lat=\''+tarlat+'\',lng=\''+tarlon+'\' where $pk=\''+ pk +'\';<br>');\n";
//echo "document.write('update $table set lat='+ lat +',lon='+ lon +' where pk=');\n";
}
//echo "}\n";
//echo "call getsql();";
}
//mysql_close($c);
//echo "\nalert('strsql');";
//echo "\ndocument.write(strsql);";
echo "\nupdate_latlng(strsql);\n";
?>
</script>
</form>
</body>

</html>
